package com.xc.controller.backend;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ag.utils.PageInfo;
import com.ag.utils.PageParam;
import com.xc.common.ServerResponse;
import com.xc.stock.domain.basic.entity.AppVersion;
import com.xc.stock.domain.basic.service.AppVersionService;
import com.xc.stock.infrastructure.db.po.QAppVersionPO;
import com.xc.stock.utils.ConditionBuilder;

/**
 *  后台用户登录
 *
 * @author xlfd
 * @email xlfd@gmail.com
 * @version 1.0  
 * @created Jun 18, 2021 11:22:41 AM
 */
@Controller
@RestController
@RequestMapping("/admin/appversion/")
public class AppVersionController {
	@Autowired AppVersionService appVersionService;
	
    @RequestMapping("/list.do")
	public ServerResponse<?> list(@RequestParam(required = false) String type, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
		QAppVersionPO q = QAppVersionPO.appVersionPO;
		ConditionBuilder builder = ConditionBuilder.builder();
		if(StringUtils.isNotBlank(type)) {
			builder.and(q.type.eq(type));
		}
		Page<AppVersion> page = appVersionService.repository().findAll(builder.build(), PageParam.of(pageNum, pageSize), q.id.desc());

        return ServerResponse.createBySuccess(PageInfo.with(page));
    }
	
    @RequestMapping("/create.do")
    public ServerResponse<?> create(AppVersion cmd) {
		AppVersion appVersion = appVersionService.create(cmd);
		return ServerResponse.createBySuccess(appVersion);
    }
	
    @RequestMapping("/modify.do")
    public ServerResponse<?> modify(AppVersion cmd) {
		AppVersion appVersion = appVersionService.modify(cmd);
		return ServerResponse.createBySuccess(appVersion);
    }
	
    @RequestMapping("/enable.do")
    public ServerResponse<?> enable(@RequestParam Integer id) {
		appVersionService.repository().setStatusEnable(id);
		return ServerResponse.createBySuccess();
    }
	
    @RequestMapping("/disable.do")
    public ServerResponse<?> disable(@RequestParam Integer id) {
		appVersionService.repository().setStatusDisable(id);
		return ServerResponse.createBySuccess();
    }
	@RequestMapping("/remove.do")
	public ServerResponse<?> remove(@RequestParam Integer id) {
		appVersionService.remove(id);
		return ServerResponse.createBySuccess();
	}
}